import { defineConfig } from 'vite'
import vue from '@vitejs/plugin-vue'
import electron from 'vite-plugin-electron'
import path from 'path'

import AutoImport from 'unplugin-auto-import/vite'
import Components from 'unplugin-vue-components/vite'
import { ElementPlusResolver } from 'unplugin-vue-components/resolvers'


export default defineConfig({
  base: './',
  plugins: [
    vue(),
    electron({
      entry: 'electron/main.js',
      vite: {
        build: {
          outDir: 'dist-electron',
          rollupOptions: {
            external: ['electron']
          }
        }
      }
    }),
    AutoImport({
      resolvers: [ElementPlusResolver()],
    }),
    Components({
      resolvers: [ElementPlusResolver()],
    })
  ],
  resolve: {
    alias: {
      '@': path.resolve(__dirname, './src')
    }
  },
  // 为开发服务器配置额外的选项
  server: {
    host: '0.0.0.0',
    port: 5173,
    proxy: {
        [process.env.VITE_API_PREFIX]: {
            target: process.env.VITE_BASE_API,
            changeOrigin: true,
            rewrite: (path) => path.replace(process.env.VITE_API_PREFIX, '')
        }
    }
  },
  build: {
    outDir: 'dist',
    emptyOutDir: true
  }
})
